import 'dart:async';
import 'dart:convert';

import 'package:badges/badges.dart';
import 'package:elephant_fish/TRTCChatSalonDemo/model/TRTCChatSalonDelegate.dart';
import 'package:elephant_fish/TRTCLiveRoomDemo/model/TRTCLiveRoomDelegate.dart';
import 'package:elephant_fish/TRTCLiveRoomDemo/ui/base/LiveImgButton.dart';
import 'package:elephant_fish/TRTCLiveRoomDemo/ui/base/LiveMessageList.dart';
import 'package:elephant_fish/TRTCLiveRoomDemo/ui/base/LiveTextButton.dart';
import 'package:elephant_fish/TRTCLiveRoomDemo/ui/base/PopUpMessageList.dart';
import 'package:elephant_fish/base/YunApiHelper.dart';
import 'package:elephant_fish/debug/GenerateTestUserSig.dart';
import 'package:elephant_fish/http/core/hi_net.dart';
import 'package:elephant_fish/http/request/attention_anchor_request.dart';
import 'package:elephant_fish/http/request/attention_room_request.dart';
import 'package:elephant_fish/http/request/base_request.dart';
import 'package:elephant_fish/http/request/down_wheat_request.dart';
import 'package:elephant_fish/http/request/notice_anchor_request.dart';
import 'package:elephant_fish/http/request/room_leaderboard_request.dart';
import 'package:elephant_fish/http/request/serving_wheat.dart';
import 'package:elephant_fish/http/request/user_details_by_userI_request.dart';
import 'package:elephant_fish/http/request/user_info_request.dart';
import 'package:elephant_fish/model/gift_entity.dart';
import 'package:elephant_fish/model/leaderboard_entity.dart';
import 'package:elephant_fish/model/user_info_entity.dart';
import 'package:elephant_fish/page/login_page.dart';
import 'package:elephant_fish/page/wallet_page.dart';
import 'package:elephant_fish/util/TxUtils.dart';
import 'package:elephant_fish/util/size_util.dart';
import 'package:elephant_fish/widget/broast_gift.dart';
import 'package:elephant_fish/widget/gift_list.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tencent_trtc_cloud/tx_audio_effect_manager.dart';
import 'package:tencent_trtc_cloud/tx_beauty_manager.dart';
import '../widget/RoomBottomBar.dart';
import '../widget/AnchorItem.dart';
import '../widget/AudienceItem.dart';
import '../widget/RoomTopMsg.dart';
import '../base/UserEnum.dart';
import '../../model/TRTCChatSalon.dart';
import '../../model/TRTCChatSalonDef.dart';

/*
 *  房间界面
 */
class VoiceRoomPage extends StatefulWidget {
  VoiceRoomPage(this.userType, {Key key}) : super(key: key);
  final UserType userType;

  @override
  State<StatefulWidget> createState() => VoiceRoomPageState();
}

List<String> giftList = [];
TRTCChatSalon trtcVoiceRoom;

class VoiceRoomPageState extends State<VoiceRoomPage>
    with TickerProviderStateMixin {
  ScrollController _scrollController = ScrollController();
  int currentRoomId;
  int currentRoomOwnerId;
  int currentLoginUserId;
  bool isBarrageON = true;
  bool isFollowed = false;
  List<RoomInfo> roomInfList = [];
  List<LeaderBorardEntity> leaderList = [];
  bool isBarrageSliderOn = false;
  bool isShield = false;
  List<String> _popupMessageList = [];
  List<List<MessageColor>> _messageLogList = [];
  bool isPKing = false;
  String pkUserId = "";
  Function onLeave;
  List<String> _popupGiftList = [];
  UserStatus userStatus = UserStatus.Mute;
  String title = "";
  UserType userType = UserType.Administrator;
  bool topMsgVisible = false;
  bool isShowTopMsgAction = false;
  String topMsg = "";
  TextEditingController inputController = new TextEditingController();
  final inputFocusNode = FocusNode();
  bool isShowComment = false;
  Map<String, bool> hadAgreeMap = {};
  bool hadHandUp = false;

  //用户信息
  UserInfoEntity userInfoEntity;

  //送礼用户信息
  UserInfoEntity userInfoEntity2;

  //主播信息
  UserInfoEntity userInfoEntity1;

  //主播列表
  Map<int, UserInfo> _anchorList = {};

  //听众列表
  Map<int, UserInfo> _audienceList = {};
  int _audienceNextSeq = 0;

  //举手列表
  Map<int, RaiseHandInfo> _raiseHandList = {};
  RaiseHandInfo _lastRaiseHandUser;

  //大声列表
  Map<int, bool> _volumeUpdateList = {};

  TXBeautyManager beautyManager;
  TXAudioEffectManager audioEffectManager;

  @override
  void initState() {
    super.initState();
    initSDK();
  }

  @override
  dispose() {
    trtcVoiceRoom.unRegisterListener(onVoiceListener);
    trtcVoiceRoom.unRegisterListener(onListenerFunc);
    super.dispose();
  }

  initSDK() async {
    trtcVoiceRoom = await TRTCChatSalon.sharedInstance();
    initUserInfo();
  }

  UserInfo _finUserInfo(int userId) {
    if (_anchorList.containsKey(userId)) return _anchorList[userId];
    if (_audienceList.containsKey(userId)) return _audienceList[userId];
    return null;
  }

  onListenerFunc(type, params) {
    switch (type) {
      case TRTCLiveRoomDelegate.onRecvRoomCustomMsg:
        {
          String command = params["command"].toString();
          if ('like' == command) {
            addMessageLog([
              MessageColor("来自 ", null),
              MessageColor(
                  params['user']['userName'].toString(), Color(0xFF3074FD)),
              MessageColor(" 的点赞", null)
            ]);
            print(params['userName']);
          } else if ('slider' == command) {
            safeSetState(() {
              _popupMessageList.add(params["message"].toString());
            });
          } else if ('gift' == command) {
            setState(() {
              const timeout = const Duration(seconds: 5);
              Timer(timeout, () {
                setState(() {
                  _popupGiftList.clear();
                });
              });
              _popupGiftList.add(params["message"].toString());
              setState(() {
                userInfoEntity2.userId = params['user']['userId'].toString();
                userInfoEntity2.nickname =
                    params['user']['userName'].toString();
                userInfoEntity2.avatar =
                    params['user']['userAvatar'].toString();
                getRoomLeaderBoard();
              });
              if (_popupGiftList.length > 3) {
                _popupGiftList.removeAt(0);
              }
            });
          }
        }
        break;
      case TRTCLiveRoomDelegate.onRecvRoomTextMsg:
        addMessageLog([
          MessageColor(params["userName"].toString(), Color(0xFFFCAF41)),
          MessageColor(": " + params["message"].toString(), null)
        ]);
        break;
      case TRTCLiveRoomDelegate.onAudienceEnter:
        {
          addMessageLog([
            MessageColor("欢迎 ", null),
            MessageColor(params["userName"].toString(), Color(0xFFF7AF97)),
            MessageColor(" 进入房间", null)
          ]);
        }
        break;
      case TRTCLiveRoomDelegate.onAudienceExit:
        {
          addMessageLog([
            MessageColor(params["userName"].toString(), Color(0xFF3CCFA5)),
            MessageColor(" 离开房间", null)
          ]);
        }
        break;
      case TRTCLiveRoomDelegate.onRoomPKAccepted:
        {
          addMessageLog([
            MessageColor(params["userName"].toString(), Color(0xFFFCAF41)),
            MessageColor(" 主播接受跨房Pk请求", null)
          ]);
          safeSetState(() {
            isPKing = true;
          });
        }
        break;
      case TRTCLiveRoomDelegate.onQuitRoomPK:
        {
          safeSetState(() {
            isPKing = false;
            pkUserId = '';
          });
          showErrorToast("断开跨房 PK ", () {});
        }
        break;
    }
  }

  showErrorToast(String message, Function callback) {
    TxUtils.showErrorToast(message, context);
    if (callback != null) {
      Future.delayed(Duration(seconds: 2), () {
        callback();
      });
    }
  }

  addMessageLog(List<MessageColor> logInfos) {
    safeSetState(() {
      _messageLogList.add(logInfos);
    });
  }

  safeSetState(callBack) {
    setState(() {
      if (mounted) {
        callBack();
      }
    });
  }

  //trtc的所有事件监听
  onVoiceListener(type, param) async {
    switch (type) {
      case TRTCChatSalonDelegate.onError:
        {
          TxUtils.showErrorToast(type.toString(), context);
          TxUtils.uploadException(
            "onVoiceListener-error",
            param.toString(),
          );
        }
        break;
      case TRTCChatSalonDelegate.onEnterRoom:
        {
          //进房
          int result = param as int;
          if (result < 0) {
            TxUtils.showErrorToast('进房失败', context);
            Navigator.pushReplacementNamed(
              context,
              "/index",
            );
            return;
          }
        }
        break;
      case TRTCChatSalonDelegate.onAgreeToSpeak:
        doOnAgreeToSpeak(param);
        break;
      case TRTCChatSalonDelegate.onRefuseToSpeak:
        doOnRefuseToSpeak(param);
        break;
      case TRTCChatSalonDelegate.onRaiseHand:
        doOnRaiseHand(param);
        break;
      case TRTCChatSalonDelegate.onKickMic:
        doOnKickMic(param);
        break;
      case TRTCChatSalonDelegate.onAudienceEnter:
        doOnAudienceEnter(param);
        break;
      case TRTCChatSalonDelegate.onExitRoom:
        {}
        break;
      case TRTCChatSalonDelegate.onAudienceExit:
        doOnAudienceExit(param);
        break;
      case TRTCChatSalonDelegate.onAnchorLeaveMic:
        {
          //主播离开房间
          doOnAnchorLeave(param);
        }
        break;
      case TRTCChatSalonDelegate.onAnchorEnterMic:
        {
          //主播进入房间
          doOnAnchorEnter(param);
        }
        break;
      case TRTCChatSalonDelegate.onMicMute:
        {
          //主播是否禁麦
          getAnchorList();
        }
        break;
      case TRTCChatSalonDelegate.onUserVolumeUpdate:
        {
          //上麦成员的音量变化
          doOnUserVolumeUpdate(param);
        }
        break;
      case TRTCChatSalonDelegate.onKickedOffline:
        {
          TxUtils.showErrorToast('已在其他地方登陆，请重新登录', context);
          Navigator.pushReplacementNamed(
            context,
            "/login",
          );
        }
        break;
      case TRTCChatSalonDelegate.onRoomDestroy:
        {
          //房间被销毁，当主播调用destroyRoom后，观众会收到该回调
          TxUtils.showErrorToast('沙龙已结束', context);
          Navigator.pushReplacementNamed(
            context,
            "/index",
          );
        }
        break;
    }
  }

  //事件处理
  //群主同意举手
  doOnAgreeToSpeak(param) {
    _closeTopMessage();
    trtcVoiceRoom.enterMic();
    int userId = int.parse(param);
    UserInfo raiseUser = _finUserInfo(userId);
    servingWheat(raiseUser.userId);
    setState(() {
      userType = UserType.Anchor;
      userStatus = UserStatus.Speaking;
    });
  }

  //群主拒绝举手
  doOnRefuseToSpeak(param) {
    _showTopMessage('抱歉，管理员没有同意您上麦', false, true);
    setState(() {
      userType = UserType.Audience;
      userStatus = UserStatus.Mute;
    });
  }

  //有观众举手，申请上麦
  doOnRaiseHand(param) {
    int userId = int.parse(param);
    UserInfo raiseUser = _finUserInfo(userId);
    if (raiseUser != null) {
      _showTopMessage(raiseUser.userName, true, false);
      RaiseHandInfo tem = new RaiseHandInfo(
          isCanAgree: true,
          userAvatar: raiseUser.userAvatar,
          userId: raiseUser.userId,
          userName: raiseUser.userName);
      Map<int, RaiseHandInfo> _newRaiseHandList = Map.from(_raiseHandList);
      _newRaiseHandList[userId] = tem;
      setState(() {
        _raiseHandList = _newRaiseHandList;
        _lastRaiseHandUser = tem;
      });
    }
  }

  ////被群主踢下麦
  doOnKickMic(param) async {
    _showTopMessage('你已被主播踢下麦', false, true);
    trtcVoiceRoom.leaveMic();
    await this.getAnchorList();
    int userId = int.parse(param);
    UserInfo raiseUser = _finUserInfo(userId);
    downWheat(raiseUser.userId);
    setState(() {
      userStatus = UserStatus.Mute;
      userType = UserType.Audience;
    });
  }

  //主播进入房间
  doOnAnchorEnter(param) {
    Map ps = param as Map;
    int userId = int.tryParse(ps['userId']);

    Map<int, UserInfo> _newAnchorList = Map.from(_anchorList);

    String userName = ps['userName'] as String;
    String userAvatar = ps['userAvatar'] as String;
    bool mute = ps['mute'] as bool;
    _newAnchorList[userId] = new UserInfo(
      userId: userId.toString(),
      mute: mute,
      userAvatar: userAvatar,
      userName: userName,
    );
    setState(() {
      _anchorList = _newAnchorList;
    });
    //更新观众
    if (_audienceList.containsKey(userId)) {
      Map<int, UserInfo> _newAudienceList = Map.from(_audienceList);
      _newAudienceList.remove(userId);
      setState(() {
        setState(() {
          _audienceList = _newAudienceList;
        });
      });
    }
  }

  //主播离开房间
  doOnAnchorLeave(param) {
    Map ps = param as Map;
    int userId = int.tryParse(ps['userId']);
    Map<int, UserInfo> _newAnchorList = Map.from(_anchorList);
    if (_newAnchorList.containsKey(userId)) {
      _newAnchorList.remove(userId);
    }
    setState(() {
      _anchorList = _newAnchorList;
    });
    //主播离开变为普通的听众
    Map<int, UserInfo> _newAudienceList = Map.from(_audienceList);
    String userName = ps['userName'] as String;
    String userAvatar = ps['userAvatar'] as String;
    bool mute = ps['mute'] as bool;
    _newAudienceList[userId] = new UserInfo(
      userId: userId.toString(),
      mute: mute,
      userAvatar: userAvatar,
      userName: userName,
    );
    setState(() {
      _audienceList = _newAudienceList;
    });
  }

  //观众进入房间
  doOnAudienceEnter(param) {
    print("==doOnAudienceEnter=" + param.toString());
    List<dynamic> list = param as List<dynamic>;
    Map<int, UserInfo> _newAudienceList = Map.from(_audienceList);
    list.forEach((element) {
      int userId = int.tryParse(element['userId']);
      String userName = element['userName'] as String;
      String userAvatar = element['userAvatar'] as String;
      _newAudienceList[userId] = new UserInfo(
          userId: userId.toString(),
          userAvatar: userAvatar,
          userName: userName);
    });
    setState(() {
      _audienceList = _newAudienceList;
    });
  }

  //观众离开房间
  doOnAudienceExit(param) {
    int userId = int.tryParse(param["userId"]);
    if (_audienceList.containsKey(userId)) {
      Map<int, UserInfo> _newAudienceList = Map.from(_audienceList);
      _newAudienceList.remove(userId);
      setState(() {
        setState(() {
          _audienceList = _newAudienceList;
        });
      });
    }
    //把主播也一起踢了
    if (_anchorList.containsKey(userId)) {
      Map<int, UserInfo> _newAnchorListList = Map.from(_anchorList);
      _newAnchorListList.remove(userId);
      setState(() {
        setState(() {
          _anchorList = _newAnchorListList;
        });
      });
    }
  }

  //上麦成员的音量变化
  doOnUserVolumeUpdate(param) async {
    List<dynamic> list = param["userVolumes"] as List<dynamic>;
    Map<int, bool> _newVolumeUpdateList = Map.from(_volumeUpdateList);
    list.forEach((item) {
      int userId = currentLoginUserId;
      int volme = int.tryParse(item["volume"].toString());
      if (item['userId'] != null && item['userId'] != "") {
        userId = int.tryParse(item['userId']);
      }
      if (_anchorList.containsKey(userId)) {
        _newVolumeUpdateList[userId] = volme > 20 ? true : false;
      }
    });
    setState(() {
      _volumeUpdateList = _newVolumeUpdateList;
    });
  }

  ///初始化用户信息
  initUserInfo() async {
    String loginUserId = await TxUtils.getLoginUserId();
    await getInitData();
    SharedPreferences prefs = await SharedPreferences.getInstance();
    userInfoEntity2 =
        UserInfoEntity.fromJson(jsonDecode(prefs.getString('USERINFO')));
    currentLoginUserId = int.tryParse(loginUserId);
    String currLoginUserId = await TxUtils.getLoginUserId();
    Map arguments = ModalRoute.of(context).settings.arguments as Map;
    int _currentRoomId = int.tryParse(arguments['roomId'].toString());
    int _currentRoomOwnerId = int.tryParse(arguments['ownerId'].toString());
    String roomName =
        arguments["roomName"] == null ? '--' : arguments["roomName"];
    final bool isAdmin =
        (_currentRoomOwnerId == userInfoEntity.userId) ? true : false;
    bool isNeedCreateRoom = false;
    trtcVoiceRoom = await TRTCChatSalon.sharedInstance();
    ActionCallback resValue = await trtcVoiceRoom.login(
      GenerateTestUserSig.sdkAppId,
      currLoginUserId,
      GenerateTestUserSig.genTestSig(currLoginUserId),
    );
    if (arguments.containsKey('isNeedCreateRoom')) {
      isNeedCreateRoom = arguments['isNeedCreateRoom'] as bool;
    }
    setState(() {
      currentRoomId = _currentRoomId;
      currentRoomOwnerId = _currentRoomOwnerId;
      userType = isAdmin ? UserType.Administrator : UserType.Audience;
      title = roomName;
    });
    if (isNeedCreateRoom) {
      String coverUrl = arguments['coverUrl'] as String;
      await this.createRoom(_currentRoomId, roomName, coverUrl);
      TxUtils.showToast('房间创建成功', context);
    } else {
      ActionCallback enterRoomResp =
          await trtcVoiceRoom.enterRoom(_currentRoomId);
      if (enterRoomResp.code == 0) {
        if (isAdmin) {
          setState(() {
            userStatus = UserStatus.Speaking;
          });
          TxUtils.showToast('房主占座成功', context);
        } else {
          TxUtils.showToast('进房成功', context);
        }
      } else {
        TxUtils.showErrorToast('enterRoom:' + enterRoomResp.desc, context);
      }
    }
    trtcVoiceRoom.registerListener(onVoiceListener);
    await getAnchorList();
    await getAudienceList();
    await getRoomAnchor();
  }

  ///创建房间
  createRoom(roomId, roomName, coverUrl) async {
    ActionCallback resp = await trtcVoiceRoom.createRoom(
      roomId,
      RoomParam(
        coverUrl: coverUrl,
        roomName: roomName,
      ),
    );
    if (resp.code == 0) {
      await YunApiHelper.createRoom(roomId.toString());
    } else {
      TxUtils.showErrorToast('createRoom:' + resp.desc, context);
    }
  }

  //获取主播列表
  getAnchorList() async {
    try {
      UserListCallback _archorResp = await trtcVoiceRoom.getArchorInfoList();
      if (_archorResp.code == 0) {
        Map<int, UserInfo> _newArchorList = {};
        _archorResp.list.forEach((item) {
          if (item.userId != null && item.userId != '') {
            _newArchorList[int.tryParse(item.userId)] = item;
          }
        });
        setState(() {
          userType = !_newArchorList.containsKey(userInfoEntity.userId)
              ? UserType.Audience
              : userType == UserType.Administrator
                  ? UserType.Administrator
                  : UserType.Anchor;
          userStatus = _newArchorList.containsKey(userInfoEntity.userId)
              ? _newArchorList[currentLoginUserId].mute
                  ? UserStatus.Mute
                  : UserStatus.Speaking
              : UserStatus.Mute;
        });

        setState(() {
          _anchorList = _newArchorList;
        });
      } else {
        TxUtils.showErrorToast(
            'getArchorInfoList:' + _archorResp.desc, context);
      }
    } catch (ex) {
      TxUtils.showErrorToast(ex.toString(), context);
    }
  }

  // 获取听众列表
  getAudienceList() async {
    try {
      MemberListCallback _memberResp = await trtcVoiceRoom.getRoomMemberList(0);
      if (_memberResp.code == 0) {
        Map<int, UserInfo> userList = {};
        _memberResp.list.forEach((item) {
          if (item.userId != null && item.userId != '') {
            int userId = int.tryParse(item.userId);
            //非主播
            if (!_anchorList.containsKey(userId)) {
              userList[userId] = item;
            }
          }
        });
        setState(() {
          _audienceList = userList;
          _audienceNextSeq = _memberResp.nextSeq;
        });
      } else {
        TxUtils.showErrorToast(
            "getRoomMemberList:" + _memberResp.desc, context);
      }
    } catch (ex) {
      TxUtils.showErrorToast(ex.toString(), context);
    }
  }

  ///获取更多听众列表
  getMoreAudienceList() async {
    try {
      if (_audienceNextSeq == 0) {
        return;
      }
      MemberListCallback _memberResp =
          await trtcVoiceRoom.getRoomMemberList(_audienceNextSeq);
      if (_memberResp.code == 0) {
        Map<int, UserInfo> userList = {};
        _memberResp.list.forEach((item) {
          if (item.userId != null && item.userId != '') {
            int userId = int.tryParse(item.userId);
            //非主播
            if (!_anchorList.containsKey(userId)) {
              userList[userId] = item;
            }
          }
        });
        setState(() {
          _audienceList.addAll(userList);
          _audienceNextSeq = _memberResp.nextSeq;
        });
      } else {
        TxUtils.showErrorToast(
            "getRoomMemberList:" + _memberResp.desc, context);
      }
    } catch (ex) {
      TxUtils.showErrorToast(ex.toString(), context);
    }
  }

  //管理员同意其成为主播
  agreeToSpeackClick({userId}) {
    String tmpUserId = '';
    if (userId != null) {
      tmpUserId = userId;
    } else {
      if (_lastRaiseHandUser != null) {
        tmpUserId = _lastRaiseHandUser.userId;
      }
    }
    if (tmpUserId != '') {
      trtcVoiceRoom.agreeToSpeak(tmpUserId);
      this._closeTopMessage();
      if (_raiseHandList.containsKey(int.parse(tmpUserId))) {
        //同意后也移除
        // this.setState(() {
        //   _raiseHandList[int.parse(tmpUserId)].isCanAgree = false;
        // });
        if (_raiseHandList.containsKey(int.parse(tmpUserId))) {
          _raiseHandList.remove(int.parse(tmpUserId));
        }
      }
    }
  }

  //管理员拒绝其成为主播
  handleAdminRefuseToSpeak({userId}) {
    String tmpUserId = '';
    if (userId != null) {
      tmpUserId = userId;
    } else {
      if (_lastRaiseHandUser != null) {
        tmpUserId = _lastRaiseHandUser.userId;
      }
    }
    if (tmpUserId != '') {
      trtcVoiceRoom.refuseToSpeak(tmpUserId);
      this._closeTopMessage();
      if (_raiseHandList.containsKey(int.parse(tmpUserId))) {
        _raiseHandList.remove(int.parse(tmpUserId));
        //_raiseHandList[int.parse(userId)].isCanAgree = false;
      }
    }
  }

  //主播下麦
  handleAnchorLeaveMic() {
    trtcVoiceRoom.leaveMic();
    //变为听众
    this.setState(() {
      userType = UserType.Audience;
    });
  }

  //音频开关
  handleMuteAudio(bool mute) {
    //设置
    trtcVoiceRoom.muteMic(mute);
    setState(() {
      //状态图标切换
      userStatus = mute ? UserStatus.Mute : UserStatus.Speaking;
    });
  }

  //听众举手
  handleRaiseHandClick() {
    trtcVoiceRoom.raiseHand();
    this._showTopMessage('举手成功！等待管理员通过~', false, true);
  }

  _showTopMessage(String message, bool showActionBtn, bool autoClose) {
    setState(() {
      topMsgVisible = true;
      topMsg = message;
      isShowTopMsgAction = showActionBtn;
    });
    if (autoClose) {
      Future.delayed(Duration(seconds: 5), () {
        this._closeTopMessage();
      });
    }
  }

  ///关闭顶部消息区
  _closeTopMessage() {
    setState(() {
      topMsgVisible = false;
      isShowTopMsgAction = false;
      topMsg = "";
    });
  }

  // 弹出退房确认对话框
  Future<bool> showExitConfirmDialog() {
    return showDialog<bool>(
        context: context,
        builder: (context) {
          return Theme(
            data: ThemeData.dark(),
            child: CupertinoAlertDialog(
              content: Container(
                child: Text(
                  userType == UserType.Administrator
                      ? '离开会解散房间，确定离开吗?'
                      : '确定离开房间吗?',
                  textAlign: TextAlign.center,
                ),
              ),
              actions: <Widget>[
                CupertinoDialogAction(
                  child: Text(
                    '再等等',
                    style: TextStyle(color: Color.fromRGBO(235, 244, 255, 1)),
                  ),
                  onPressed: () {
                    Navigator.of(context).pop(false);
                  },
                ),
                CupertinoDialogAction(
                  child: Text(
                    '我确定',
                    style: TextStyle(color: Color.fromRGBO(0, 98, 227, 1)),
                  ),
                  onPressed: () {
                    if (userType == UserType.Administrator) {
                      // YunApiHelper.destroyRoom(currentRoomId.toString())
                      //     .then((value) {
                      //   trtcVoiceRoom.destroyRoom().then((value) {
                      //     Navigator.of(context).pop(true);
                      //   });
                      // });
                      Navigator.pushReplacementNamed(
                        context,
                        "/index",
                      );
                    } else {
                      Navigator.pushReplacementNamed(
                        context,
                        "/index",
                      );
                      // trtcVoiceRoom.exitRoom().then((value) {
                      //   Navigator.of(context).pop(true);
                      // });
                    }
                  },
                ),
              ],
            ),
          );
        });
  }

  Widget getAnchorListWidget(BuildContext context) {
    return Container(
      height: _anchorList.length == 0 ? 30 : 140,
      padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
      constraints: BoxConstraints(
        minHeight: _anchorList.length == 0 ? 30 : 140,
      ),
      width: MediaQuery.of(context).size.width,
      child: GridView(
        gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
          maxCrossAxisExtent: 135.0,
          mainAxisSpacing: 20,
          crossAxisSpacing: 15, //水平间隔
          childAspectRatio: 1.0,
        ),
        children: _anchorList.values.map((UserInfo _anchorItem) {
          int thisUserId = int.tryParse(_anchorItem.userId);
          bool isVolumeUpdate = (_volumeUpdateList.containsKey(thisUserId)
              ? _volumeUpdateList[thisUserId]
              : false);
          return AnchorItem(
            roomOwnerId: currentRoomOwnerId,
            isVolumeUpdate: isVolumeUpdate,
            userName:
                _anchorItem.userName != null && _anchorItem.userAvatar != ''
                    ? _anchorItem.userName
                    : '--',
            userImgUrl:
                _anchorItem.userAvatar != null && _anchorItem.userAvatar != ''
                    ? _anchorItem.userAvatar
                    : TxUtils.getRandoAvatarUrl(),
            isAdministrator: thisUserId == currentRoomOwnerId ? true : false,
            isMute: _anchorItem.mute,
            userId: _anchorItem.userId,
            onKickOutUser: () {
              //踢人
              trtcVoiceRoom.kickMic(_anchorItem.userId);
            },
          );
        }).toList()
          ..sort((left, right) {
            if (left.isAdministrator) return -1;
            return 1;
          }),
      ),
    );
  }

  Widget getAudienceListWidget(BuildContext context) {
    List<UserInfo> list = _audienceList.values.toList();
    return Expanded(
      flex: 2,
      child: GridView.builder(
        padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
        gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
          maxCrossAxisExtent: 100.0,
          mainAxisSpacing: 10,
          crossAxisSpacing: 15,
          childAspectRatio: 0.9,
        ),
        itemCount: list.length,
        itemBuilder: (context, int index) {
          if (index == (list.length - 1)) {
            this.getMoreAudienceList();
          }
          var _audienceItem = list[index];
          var buildItem = AudienceItem(
            userImgUrl: _audienceItem.userAvatar != null &&
                    _audienceItem.userAvatar != ''
                ? _audienceItem.userAvatar
                : TxUtils.getRandoAvatarUrl(),
            userName:
                _audienceItem.userName != null && _audienceItem.userName != ''
                    ? _audienceItem.userName
                    : '--',
          );
          return buildItem;
        },
      ),
    );
  }

  ///发送消息
  onSubmitted(String messageVal, context) async {
    if (messageVal == '') {
      return;
    }
    if (isBarrageSliderOn) {
      trtcVoiceRoom.sendRoomCustomMsg("slider", messageVal);
      safeSetState(() {
        _popupMessageList.add(messageVal);
      });
    } else {
      trtcVoiceRoom.sendRoomTextMsg(messageVal);
    }
    addMessageLog(
      [MessageColor("我: ", Color(0xFFFC6091)), MessageColor(messageVal, null)],
    );
    TxUtils.showToast("发送成功", context);
    inputController.clear();
    safeSetState(() {
      isShowComment = false;
    });
  }

  ///聊天框
  Widget getInputMessage() {
    return Row(
      children: [
        Expanded(
          flex: 2,
          child: TextField(
            cursorHeight: 25,
            controller: inputController,
            focusNode: inputFocusNode,
            onSubmitted: (s) {
              onSubmitted(s, context);
            },
            onChanged: (value) {
              inputController.text = value;
              inputController.selection = TextSelection.fromPosition(
                TextPosition(
                    affinity: TextAffinity.downstream, offset: value.length),
              );
            },
            autofocus: true,
            autocorrect: false,
            textAlign: TextAlign.left,
            keyboardType: TextInputType.multiline,
            textInputAction: TextInputAction.send,
            cursorColor: Color(0x006fff),
            decoration: InputDecoration(
              border: InputBorder.none,
              isCollapsed: true,
              isDense: true,
              hintText: "和大家说点什么吧…",
              contentPadding: EdgeInsets.only(
                top: 0,
                bottom: 5,
              ),
            ),
            style: TextStyle(fontSize: 16, color: Colors.white70),
            minLines: 1,
          ),
        ),
        LiveTextButton(
            text: "发送",
            onPressed: () {
              onSubmitted(inputController.text, context);
            }),
      ],
    );
  }

  ///礼物分类背包
  onGiftSettingTap() {
    safeSetState(() {
      showModalBottomSheet(
          context: context,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(20),
              topRight: Radius.circular(20),
            ),
          ),
          builder: (BuildContext context) {
            return Container(
              child: BroastGift(
                roomId: currentRoomId,
                isShield: isShield,
                userId: userInfoEntity1.userId1,
              ),
            );
          }).then((_) => safeSetState(() {
            getRoomLeaderBoard();
            _popupGiftList = giftList;
            var timeout = Duration(seconds: 5);
            Timer(timeout, () {
              setState(() {
                _popupGiftList.clear();
              });
            });
          }));
    });
  }

  onCommentTap() {
    safeSetState(() {
      isShowComment = true;
    });
  }

  ///展示举手列表
  onShowHandList(raiseHandList) {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext context) {
        return StatefulBuilder(
          builder: (context, setState) => Container(
            color: Color.fromRGBO(19, 35, 63, 1),
            child: CustomScrollView(
              slivers: [
                SliverAppBar(
                  leading: Text(''),
                  pinned: true,
                  backgroundColor: Color.fromRGBO(19, 35, 63, 1),
                  shadowColor: Color.fromRGBO(19, 35, 63, 1),
                  title: Text(
                    '举手列表',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                SliverFixedExtentList(
                  itemExtent: 75.0,
                  delegate: SliverChildBuilderDelegate(
                    (BuildContext context, int index) {
                      //创建列表项
                      RaiseHandInfo userInfo = raiseHandList[index];
                      return Container(
                        alignment: Alignment.centerLeft,
                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Expanded(
                              flex: 0,
                              child: Padding(
                                  padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
                                  child: ClipRRect(
                                    borderRadius: BorderRadius.circular(44),
                                    child: Image.network(
                                      userInfo.userAvatar != null &&
                                              userInfo.userAvatar != ''
                                          ? userInfo.userAvatar
                                          : TxUtils.getRandoAvatarUrl(),
                                      height: 44,
                                      fit: BoxFit.fitHeight,
                                    ),
                                  )),
                            ),
                            Expanded(
                              flex: 1,
                              child: Padding(
                                padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
                                child: Text(
                                  userInfo.userName,
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 16,
                                  ),
                                ),
                              ),
                            ),
                            Expanded(
                              flex: 0,
                              child: InkWell(
                                onTap: () {
                                  //同意or拒绝
                                  Navigator.pop(context);
                                  if (userInfo.isCanAgree) {
                                    agreeToSpeackClick(userId: userInfo.userId);
                                    this.setState(() {
                                      hadAgreeMap[userInfo.userId] = true;
                                    });
                                  }
                                },
                                child: Padding(
                                  padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
                                  child: Image.asset(
                                    hadAgreeMap.containsKey(userInfo.userId)
                                        ? "assets/images/after-HandUp.png"
                                        : userInfo.isCanAgree
                                            ? "assets/images/before-HandUp.png"
                                            : "assets/images/after-HandUp.png",
                                    height: 30,
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      );
                    },
                    childCount: raiseHandList.length,
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  ///底部按钮区域
  Widget getgetRoomBottomBar() {
    String lastBtnUrl = "assets/images/no-speaking.png";
    if (UserType.Audience == userType) {
      lastBtnUrl = hadHandUp
          ? "assets/images/raiseHand.png"
          : "assets/images/noRaiseHand.png";
    } else {
      lastBtnUrl = userStatus == UserStatus.Mute
          ? "assets/images/no-speaking.png"
          : "assets/images/speaking.png";
    }

    String secondBtnUrl = userType == UserType.Administrator
        ? "assets/images/raiseHandList.png"
        : userType == UserType.Anchor
            ? "assets/images/DownWheat.png"
            : "";
    int validRaiseHandCount = 0;
    if (_raiseHandList.values.toList() != null) {
      _raiseHandList.values.toList().forEach((element) {
        if (element.isCanAgree) validRaiseHandCount = validRaiseHandCount + 1;
      });
    }
    List<Widget> btnList = [];
    if (UserType.Audience == userType) {
      btnList = [
        LiveImgButton(
          imgUrl: "assets/images/liveRoom/Comment.png",
          imgSize: 35,
          onTap: () {
            onCommentTap();
          },
        ),
        Container(
          child: InkWell(
            onTap: () {
              if (UserType.Administrator == userType)
                onShowHandList(_raiseHandList.values.toList());
            },
            child: validRaiseHandCount > 0
                ? Badge(
                    position: BadgePosition.topStart(),
                    badgeContent: Text(
                      validRaiseHandCount.toString(),
                    ),
                    child: secondBtnUrl == ''
                        ? Container(
                            width: 0,
                            height: 0,
                          )
                        : Image.asset(
                            secondBtnUrl,
                            width: 35.0,
                          ),
                  )
                : secondBtnUrl == ''
                    ? Container(
                        width: 0,
                        height: 0,
                      )
                    : Image.asset(
                        secondBtnUrl,
                        width: 35.0,
                      ),
          ),
        ),
        // LiveImgButton(
        //   imgUrl: "assets/images/liveRoom/PK.png",
        //   imgSize: 52,
        //   onTap: () {
        //     onShowPkUserList();
        //   },
        // ),
        LiveImgButton(
          imgUrl: lastBtnUrl,
          imgSize: 35,
          onTap: () {
            if (UserType.Audience == userType) {
              onHandUp();
            } else {
              onMuteAudioClick(userStatus == UserStatus.Mute ? false : true);
            }
          },
        ),
        //送礼物
        LiveImgButton(
          imgUrl: "assets/images/liveRoom/gift_icon.png",
          imgSize: 35,
          onTap: () {
            // onMusicSettingTap();
            onGiftSettingTap().then((_) => setState(() {
                  _popupGiftList = giftList;
                }));
          },
        ),
        //充值
        LiveImgButton(
          imgUrl: "assets/images/chong.png",
          imgSize: 35,
          onTap: () {
            Navigator.of(context)
                .push(MaterialPageRoute(builder: (context) => WalletPage()));
          },
        ),
      ];
    } else {
      btnList = [
        LiveImgButton(
          imgUrl: "assets/images/liveRoom/Comment.png",
          imgSize: 35,
          onTap: () {
            onCommentTap();
          },
        ),
        Container(
          child: InkWell(
            onTap: () {
              if (UserType.Administrator == userType)
                onShowHandList(_raiseHandList.values.toList());
            },
            child: validRaiseHandCount > 0
                ? Badge(
                    position: BadgePosition.topStart(),
                    badgeContent: Text(
                      validRaiseHandCount.toString(),
                    ),
                    child: secondBtnUrl == ''
                        ? Container(
                            width: 0,
                            height: 0,
                          )
                        : Image.asset(
                            secondBtnUrl,
                            width: 35.0,
                          ),
                  )
                : secondBtnUrl == ''
                    ? Container(
                        width: 0,
                        height: 0,
                      )
                    : Image.asset(
                        secondBtnUrl,
                        width: 35.0,
                      ),
          ),
        ),
        LiveImgButton(
          imgUrl: lastBtnUrl,
          imgSize: 35,
          onTap: () {
            if (UserType.Audience == userType) {
              onHandUp();
            } else {
              onMuteAudioClick(userStatus == UserStatus.Mute ? false : true);
            }
          },
        ),
        //送礼物
        LiveImgButton(
          imgUrl: "assets/images/liveRoom/gift_icon.png",
          imgSize: 35,
          onTap: () {
            // onMusicSettingTap();
            onGiftSettingTap().then((_) => setState(() {
                  _popupGiftList = giftList;
                }));
          },
        ),
        //充值
        LiveImgButton(
          imgUrl: "assets/images/chong.png",
          imgSize: 35,
          onTap: () {
            Navigator.of(context)
                .push(MaterialPageRoute(builder: (context) => WalletPage()));
          },
        ),
      ];
    }
    return Container(
      margin: EdgeInsets.only(bottom: 15),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.max,
        children: btnList,
      ),
    );
  }

  ///顶部按钮区域
  Widget getTopBtnList() {
    List<Widget> btnList = [
      // leaderList == null
      //     ? Container(
      //   width: 0,
      //   height: 0,
      // )
      //     : leaderList.length >= 1
      //     ? Container(
      //   width: SizeUtil.px(64),
      //   height: SizeUtil.px(64),
      //   child: Stack(
      //     children: [
      //       CircleAvatar(
      //         backgroundImage: NetworkImage(
      //             'http://119.28.131.94:82' +
      //                 leaderList[0].avatar),
      //         radius: 16,
      //       ),
      //       Align(
      //         alignment: Alignment.bottomCenter,
      //         child: Container(
      //           width: SizeUtil.px(56),
      //           height: SizeUtil.px(21),
      //           decoration: BoxDecoration(
      //             borderRadius: BorderRadius.all(
      //                 Radius.circular(SizeUtil.px(28))),
      //             gradient: LinearGradient(
      //               begin: Alignment.topCenter,
      //               end: Alignment.bottomCenter,
      //               colors: [
      //                 Color(0x80fea84a),
      //                 Color(0x80f4840c)
      //               ],
      //             ),
      //           ),
      //           child: Center(
      //             child: Text(
      //               leaderList[0].gold,
      //               style: TextStyle(
      //                   color: Color(0xffffffff),
      //                   fontSize: SizeUtil.px(12)),
      //             ),
      //           ),
      //         ),
      //       ),
      //       Align(
      //           alignment: Alignment.topRight,
      //           child: Image.asset(
      //             'assets/images/gold_crown.png',
      //             width: SizeUtil.px(24),
      //             height: SizeUtil.px(24),
      //           ))
      //     ],
      //   ),
      // )
      //     : Container(
      //   width: 0,
      //   height: 0,
      // ),
      // leaderList.length >= 2
      //     ? Container(
      //   width: SizeUtil.px(64),
      //   height: SizeUtil.px(64),
      //   child: Stack(
      //     children: [
      //       CircleAvatar(
      //         backgroundImage: NetworkImage(
      //             'http://119.28.131.94:82' + leaderList[1].avatar),
      //         radius: 16,
      //       ),
      //       Align(
      //         alignment: Alignment.bottomCenter,
      //         child: Container(
      //           width: SizeUtil.px(56),
      //           height: SizeUtil.px(21),
      //           decoration: BoxDecoration(
      //             borderRadius: BorderRadius.all(
      //                 Radius.circular(SizeUtil.px(28))),
      //             gradient: LinearGradient(
      //               begin: Alignment.topCenter,
      //               end: Alignment.bottomCenter,
      //               colors: [Color(0x80fea84a), Color(0x80f4840c)],
      //             ),
      //           ),
      //           child: Center(
      //             child: Text(
      //               leaderList[1].gold,
      //               style: TextStyle(
      //                   color: Color(0xffffffff),
      //                   fontSize: SizeUtil.px(12)),
      //             ),
      //           ),
      //         ),
      //       ),
      //       Align(
      //           alignment: Alignment.topRight,
      //           child: Image.asset(
      //             'assets/images/sliver_crown.png',
      //             width: SizeUtil.px(24),
      //             height: SizeUtil.px(24),
      //           ))
      //     ],
      //   ),
      // )
      //     : Container(
      //   width: 0,
      //   height: 0,
      // ),
      // leaderList.length >= 3
      //     ? Container(
      //   width: SizeUtil.px(64),
      //   height: SizeUtil.px(64),
      //   child: Stack(
      //     children: [
      //       CircleAvatar(
      //         backgroundImage: NetworkImage(
      //             'http://119.28.131.94:82' + leaderList[2].avatar),
      //         radius: 16,
      //       ),
      //       Align(
      //         alignment: Alignment.bottomCenter,
      //         child: Container(
      //           width: SizeUtil.px(56),
      //           height: SizeUtil.px(21),
      //           decoration: BoxDecoration(
      //             borderRadius: BorderRadius.all(
      //                 Radius.circular(SizeUtil.px(28))),
      //             gradient: LinearGradient(
      //               begin: Alignment.topCenter,
      //               end: Alignment.bottomCenter,
      //               colors: [Color(0x80fea84a), Color(0x80f4840c)],
      //             ),
      //           ),
      //           child: Center(
      //             child: Text(
      //               leaderList[2].gold,
      //               style: TextStyle(
      //                   color: Color(0xffffffff),
      //                   fontSize: SizeUtil.px(12)),
      //             ),
      //           ),
      //         ),
      //       ),
      //       Align(
      //           alignment: Alignment.topRight,
      //           child: Image.asset(
      //             'assets/images/copper_crown.png',
      //             width: SizeUtil.px(24),
      //             height: SizeUtil.px(24),
      //           ))
      //     ],
      //   ),
      // )
      //     : Container(
      //   width: 0,
      //   height: 0,
      // ),
      Container(
        width: SizeUtil.px(83),
        height: SizeUtil.px(52),
        decoration: BoxDecoration(
            color: Color(0x20f3f3f3),
            borderRadius: BorderRadius.all(Radius.circular(SizeUtil.px(25)))),
        child: Center(
          child: Text(
            '100',
            style: TextStyle(color: Color(0xffffffff)),
          ),
        ),
      ),
    ];
    return Container(
        margin: EdgeInsets.only(top: 60, left: 300, right: 60),
        child: Row(
          children: btnList,
        ));
  }

  onHandUp() {
    setState(() {
      hadHandUp = true;
    });
    handleRaiseHandClick();
  }

  onMuteAudioClick(bool isMute) {
    handleMuteAudio(isMute);
  }

  onExit() async {
    bool isOk = (await showExitConfirmDialog());
    if (isOk) {
      Navigator.pushReplacementNamed(context, 'index');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        // appBar: AppBar(
        //   title: Text(title + '($currentRoomId)'),
        //   leading: IconButton(
        //     icon: Icon(Icons.arrow_back_ios), //color: Colors.black
        //     onPressed: () async {
        //       bool isOk = (await this.showExitConfirmDialog())!;
        //       if (isOk) {
        //         Navigator.pushReplacementNamed(context, '/chatSalon/list');
        //       }
        //     },
        //   ),
        //   centerTitle: true,
        //   elevation: 0,
        //   backgroundColor: Color.fromRGBO(19, 41, 75, 1),
        // ),
        resizeToAvoidBottomInset: false,
        body: WillPopScope(
          onWillPop: () async {
            bool isOk = (await this.showExitConfirmDialog());
            if (isOk) {
              Navigator.pushReplacementNamed(context, 'index');
            }
            return isOk;
          },
          child: ConstrainedBox(
            constraints: BoxConstraints.expand(),
            child: Stack(
              alignment: Alignment.topLeft,
              fit: StackFit.expand,
              children: <Widget>[
                Container(
                  alignment: Alignment.topLeft,
                  child: Flex(
                    direction: Axis.vertical,
                    children: <Widget>[
                      RoomTopMessage(
                        message: topMsg,
                        visible: topMsgVisible,
                        isShowBtn: isShowTopMsgAction,
                        okTitle: '欢迎',
                        cancelTitle: '忽略',
                        onCancelTab: () {
                          this.handleAdminRefuseToSpeak();
                        },
                        onOkTab: () {
                          this.agreeToSpeackClick();
                        },
                      ),
                      // Container(
                      //   margin: EdgeInsets.fromLTRB(0, 15, 0, 0),
                      //   child: DescriptionTitle("assets/images/Anchor_ICON.png",
                      //       Languages.of(context)!.anchor),
                      // ),
                    ],
                  ),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.topRight,
                      end: Alignment.bottomLeft,
                      stops: [0.0, 1.0],
                      colors: [
                        Color.fromRGBO(19, 41, 75, 1),
                        Color.fromRGBO(0, 0, 0, 1),
                      ],
                    ),
                  ),
                ),

                Padding(
                  padding: EdgeInsets.only(top: 54.5, right: 8.5),
                  child: Align(
                    alignment: Alignment.topRight,
                    child: LiveImgButton(
                      imgUrl: "assets/images/liveRoom/closeRoom.png",
                      onTap: () {
                        onExit();
                      },
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment.topLeft,
                  child: Padding(
                    padding: EdgeInsets.only(top: 50),
                    child: Container(
                      width: 190,
                      height: 44,
                      decoration: BoxDecoration(
                          color: Color(0x10ffffff),
                          borderRadius: BorderRadius.only(
                              bottomRight: Radius.circular(22),
                              topRight: Radius.circular(22))),
                      child: Row(
                        children: [
                          SizedBox(
                            width: 14.5,
                          ),
                          CircleAvatar(
                            backgroundImage: NetworkImage(
                              _anchorList.values.toList().isEmpty
                                  ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                  : _anchorList.values.toList()[0] == null
                                      ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                      : _anchorList.values
                                          .toList()[0]
                                          .userAvatar,
                            ),
                            radius: 15,
                          ),
                          SizedBox(
                            width: 3.5,
                          ),
                          Column(
                            children: [
                              Text(
                                title,
                                style: TextStyle(
                                    color: Color(0xffffffff), fontSize: 16),
                              ),
                              SizedBox(
                                height: 1,
                              ),
                              Text(
                                '房间ID:' + '$currentRoomId',
                                style: TextStyle(
                                    color: Color(0xffffffff), fontSize: 10),
                              ),
                            ],
                          ),
                          SizedBox(
                            width: 10,
                          ),
                          isFollowed
                              ? Container(
                                  width: 60,
                                  height: 20,
                                  decoration: BoxDecoration(
                                      color: Color(0xfffc6091),
                                      borderRadius:
                                          BorderRadius.all(Radius.circular(5))),
                                  child: Center(
                                    child: Text(
                                      '已关注',
                                      style:
                                          TextStyle(color: Color(0xfff3f3f3)),
                                    ),
                                  ),
                                )
                              : InkWell(
                                  child: Image.asset(
                                    'assets/images/yuyin_add.png',
                                    width: 19.22,
                                    height: 19.22,
                                  ),
                                  onTap: () {
                                    attentionAnchor();
                                  },
                                )
                        ],
                      ),
                    ),
                  ),
                ),
                Align(
                  alignment: Alignment.topLeft,
                  child: getTopBtnList(),
                ),
                // this.getAnchorListWidget(context),
                // // DescriptionTitle("assets/images/Audience_ICON.png",
                // //     Languages.of(context)!.audience),
                // this.getAudienceListWidget(context),

                // Container(
                //   height: 60,
                // ),

                Padding(
                  padding: EdgeInsets.only(top: 160),
                  child: Align(
                      alignment: Alignment.topCenter,
                      child: _anchorList.values.toList().length >= 1
                          ? InkWell(
                              child: Container(
                                height: 120,
                                child: Column(
                                  children: [
                                    Stack(
                                      children: [
                                        Padding(
                                          padding: EdgeInsets.only(
                                              top: 18, left: 11),
                                          child: CircleAvatar(
                                            radius: 32,
                                            backgroundImage: NetworkImage(_anchorList
                                                    .values
                                                    .toList()
                                                    .isEmpty
                                                ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                : _anchorList.values
                                                            .toList()[0] ==
                                                        null
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[0]
                                                        .userAvatar),
                                          ),
                                        ),
                                        Container(
                                          width: 88,
                                          height: 88,
                                          decoration: BoxDecoration(
                                            image: DecorationImage(
                                                image: AssetImage(
                                                    'assets/images/yuyinzhubo.png')),
                                          ),
                                        ),
                                        Padding(
                                          padding: EdgeInsets.only(
                                              top: 76, left: 20),
                                          child: Container(
                                            width: 45,
                                            height: 15,
                                            decoration: BoxDecoration(
                                                color: Color(0x80707070),
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(7.5))),
                                            child: Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.center,
                                              children: [
                                                Image.asset(
                                                  'assets/images/yuyinheart.png',
                                                  width: 8,
                                                  height: 7.5,
                                                ),
                                                SizedBox(
                                                  width: 2,
                                                ),
                                                Text(
                                                  '1672',
                                                  style: TextStyle(
                                                      color: Color(0xffffffff),
                                                      fontSize: 9),
                                                )
                                              ],
                                            ),
                                          ),
                                        ),
                                      ],
                                    ),
                                    SizedBox(
                                      height: 3.5,
                                    ),
                                    Text(
                                      _anchorList.values.toList().isEmpty
                                          ? '章鱼小丸子'
                                          : _anchorList.values.toList()[0] ==
                                                  null
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[0]
                                                  .userName,
                                      style: TextStyle(
                                          color: Color(0xffffffff),
                                          fontSize: 9),
                                    )
                                  ],
                                ),
                              ),
                              onTap: () {
                                if (_anchorList.values.toList().isNotEmpty &&
                                    _anchorList.values.toList()[0] != null) {
                                  //底部弹窗
                                  showBottomSheet();
                                }
                              },
                            )
                          : Container(
                              width: 0,
                              height: 0,
                            )),
                ),
                Padding(
                  padding: EdgeInsets.only(top: 280),
                  child: Align(
                    alignment: Alignment.topCenter,
                    child: Column(
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Column(
                              children: [
                                Stack(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.only(top: 18),
                                      child: CircleAvatar(
                                        radius: 32,
                                        backgroundImage: _anchorList.values
                                                    .toList()
                                                    .length >=
                                                2
                                            ? _anchorList.values.toList()[1] ==
                                                    null
                                                ? AssetImage(
                                                    'assets/images/yuyinempty.png')
                                                : NetworkImage(_anchorList
                                                            .values
                                                            .toList()[1]
                                                            .userAvatar ==
                                                        ''
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[1]
                                                        .userAvatar)
                                            : AssetImage(
                                                'assets/images/yuyinempty.png'),
                                      ),
                                    ),
                                    _anchorList.values.toList().length >= 2
                                        ? _anchorList.values.toList()[1] == null
                                            ? Container(
                                                width: 0,
                                                height: 0,
                                              )
                                            : Padding(
                                                padding: EdgeInsets.only(
                                                    top: 76, left: 10),
                                                child: Container(
                                                  width: 45,
                                                  height: 15,
                                                  decoration: BoxDecoration(
                                                      color: Color(0x80707070),
                                                      borderRadius:
                                                          BorderRadius.all(
                                                              Radius.circular(
                                                                  7.5))),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    children: [
                                                      Image.asset(
                                                        'assets/images/yuyinheart.png',
                                                        width: 8,
                                                        height: 7.5,
                                                      ),
                                                      SizedBox(
                                                        width: 2,
                                                      ),
                                                      Text(
                                                        '1672',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0xffffffff),
                                                            fontSize: 9),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              )
                                        : Container(
                                            width: 0,
                                            height: 0,
                                          ),
                                  ],
                                ),
                                SizedBox(
                                  height: 3.5,
                                ),
                                Text(
                                  _anchorList.values.toList().length >= 2
                                      ? _anchorList.values.toList()[1] == null
                                          ? ''
                                          : _anchorList.values
                                                      .toList()[1]
                                                      .userName ==
                                                  ''
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[1]
                                                  .userName
                                      : '',
                                  style: TextStyle(
                                      color: Color(0xffffffff), fontSize: 9),
                                )
                              ],
                            ),
                            SizedBox(
                              width: 33,
                            ),
                            Column(
                              children: [
                                Stack(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.only(top: 18),
                                      child: CircleAvatar(
                                        radius: 32,
                                        backgroundImage: _anchorList.values
                                                    .toList()
                                                    .length >=
                                                3
                                            ? _anchorList.values.toList()[2] ==
                                                    null
                                                ? AssetImage(
                                                    'assets/images/yuyinempty.png')
                                                : NetworkImage(_anchorList
                                                            .values
                                                            .toList()[2]
                                                            .userAvatar ==
                                                        ''
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[2]
                                                        .userAvatar)
                                            : AssetImage(
                                                'assets/images/yuyinempty.png'),
                                      ),
                                    ),
                                    _anchorList.values.toList().length >= 3
                                        ? _anchorList.values.toList()[2] == null
                                            ? Container(
                                                width: 0,
                                                height: 0,
                                              )
                                            : Padding(
                                                padding: EdgeInsets.only(
                                                    top: 76, left: 10),
                                                child: Container(
                                                  width: 45,
                                                  height: 15,
                                                  decoration: BoxDecoration(
                                                      color: Color(0x80707070),
                                                      borderRadius:
                                                          BorderRadius.all(
                                                              Radius.circular(
                                                                  7.5))),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    children: [
                                                      Image.asset(
                                                        'assets/images/yuyinheart.png',
                                                        width: 8,
                                                        height: 7.5,
                                                      ),
                                                      SizedBox(
                                                        width: 2,
                                                      ),
                                                      Text(
                                                        '1672',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0xffffffff),
                                                            fontSize: 9),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              )
                                        : Container(
                                            width: 0,
                                            height: 0,
                                          ),
                                  ],
                                ),
                                SizedBox(
                                  height: 3.5,
                                ),
                                Text(
                                  _anchorList.values.toList().length >= 3
                                      ? _anchorList.values.toList()[2] == null
                                          ? ''
                                          : _anchorList.values
                                                      .toList()[2]
                                                      .userName ==
                                                  ''
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[2]
                                                  .userName
                                      : '',
                                  style: TextStyle(
                                      color: Color(0xffffffff), fontSize: 9),
                                )
                              ],
                            ),
                            SizedBox(
                              width: 33,
                            ),
                            Column(
                              children: [
                                Stack(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.only(top: 18),
                                      child: CircleAvatar(
                                        radius: 32,
                                        backgroundImage: _anchorList.values
                                                    .toList()
                                                    .length >=
                                                4
                                            ? _anchorList.values.toList()[3] ==
                                                    null
                                                ? AssetImage(
                                                    'assets/images/yuyinempty.png')
                                                : NetworkImage(_anchorList
                                                            .values
                                                            .toList()[3]
                                                            .userAvatar ==
                                                        ''
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[3]
                                                        .userAvatar)
                                            : AssetImage(
                                                'assets/images/yuyinempty.png'),
                                      ),
                                    ),
                                    _anchorList.values.toList().length >= 4
                                        ? _anchorList.values.toList()[3] == null
                                            ? Container(
                                                width: 0,
                                                height: 0,
                                              )
                                            : Padding(
                                                padding: EdgeInsets.only(
                                                    top: 76, left: 10),
                                                child: Container(
                                                  width: 45,
                                                  height: 15,
                                                  decoration: BoxDecoration(
                                                      color: Color(0x80707070),
                                                      borderRadius:
                                                          BorderRadius.all(
                                                              Radius.circular(
                                                                  7.5))),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    children: [
                                                      Image.asset(
                                                        'assets/images/yuyinheart.png',
                                                        width: 8,
                                                        height: 7.5,
                                                      ),
                                                      SizedBox(
                                                        width: 2,
                                                      ),
                                                      Text(
                                                        '1672',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0xffffffff),
                                                            fontSize: 9),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              )
                                        : Container(
                                            width: 0,
                                            height: 0,
                                          ),
                                  ],
                                ),
                                SizedBox(
                                  height: 3.5,
                                ),
                                Text(
                                  _anchorList.values.toList().length >= 4
                                      ? _anchorList.values.toList()[3] == null
                                          ? ''
                                          : _anchorList.values
                                                      .toList()[3]
                                                      .userName ==
                                                  ''
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[3]
                                                  .userName
                                      : '',
                                  style: TextStyle(
                                      color: Color(0xffffffff), fontSize: 9),
                                )
                              ],
                            ),
                            SizedBox(
                              width: 33,
                            ),
                            Column(
                              children: [
                                Stack(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.only(top: 18),
                                      child: CircleAvatar(
                                        radius: 32,
                                        backgroundImage: _anchorList.values
                                                    .toList()
                                                    .length >=
                                                5
                                            ? _anchorList.values.toList()[4] ==
                                                    null
                                                ? AssetImage(
                                                    'assets/images/yuyinempty.png')
                                                : NetworkImage(_anchorList
                                                            .values
                                                            .toList()[4]
                                                            .userAvatar ==
                                                        ''
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[4]
                                                        .userAvatar)
                                            : AssetImage(
                                                'assets/images/yuyinempty.png'),
                                      ),
                                    ),
                                    _anchorList.values.toList().length >= 5
                                        ? _anchorList.values.toList()[4] == null
                                            ? Container(
                                                width: 0,
                                                height: 0,
                                              )
                                            : Padding(
                                                padding: EdgeInsets.only(
                                                    top: 76, left: 10),
                                                child: Container(
                                                  width: 45,
                                                  height: 15,
                                                  decoration: BoxDecoration(
                                                      color: Color(0x80707070),
                                                      borderRadius:
                                                          BorderRadius.all(
                                                              Radius.circular(
                                                                  7.5))),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    children: [
                                                      Image.asset(
                                                        'assets/images/yuyinheart.png',
                                                        width: 8,
                                                        height: 7.5,
                                                      ),
                                                      SizedBox(
                                                        width: 2,
                                                      ),
                                                      Text(
                                                        '1672',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0xffffffff),
                                                            fontSize: 9),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              )
                                        : Container(
                                            width: 0,
                                            height: 0,
                                          ),
                                  ],
                                ),
                                SizedBox(
                                  height: 3.5,
                                ),
                                Text(
                                  _anchorList.values.toList().length >= 5
                                      ? _anchorList.values.toList()[4] == null
                                          ? ''
                                          : _anchorList.values
                                                      .toList()[4]
                                                      .userName ==
                                                  ''
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[4]
                                                  .userName
                                      : '',
                                  style: TextStyle(
                                      color: Color(0xffffffff), fontSize: 9),
                                )
                              ],
                            )
                          ],
                        ),
                        SizedBox(
                          height: 20,
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Column(
                              children: [
                                Stack(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.only(top: 18),
                                      child: CircleAvatar(
                                        radius: 32,
                                        backgroundImage: _anchorList.values
                                                    .toList()
                                                    .length >=
                                                6
                                            ? _anchorList.values.toList()[5] ==
                                                    null
                                                ? AssetImage(
                                                    'assets/images/yuyinempty.png')
                                                : NetworkImage(_anchorList
                                                            .values
                                                            .toList()[5]
                                                            .userAvatar ==
                                                        ''
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[5]
                                                        .userAvatar)
                                            : AssetImage(
                                                'assets/images/yuyinempty.png'),
                                      ),
                                    ),
                                    _anchorList.values.toList().length >= 6
                                        ? _anchorList.values.toList()[5] == null
                                            ? Container(
                                                width: 0,
                                                height: 0,
                                              )
                                            : Padding(
                                                padding: EdgeInsets.only(
                                                    top: 76, left: 10),
                                                child: Container(
                                                  width: 45,
                                                  height: 15,
                                                  decoration: BoxDecoration(
                                                      color: Color(0x80707070),
                                                      borderRadius:
                                                          BorderRadius.all(
                                                              Radius.circular(
                                                                  7.5))),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    children: [
                                                      Image.asset(
                                                        'assets/images/yuyinheart.png',
                                                        width: 8,
                                                        height: 7.5,
                                                      ),
                                                      SizedBox(
                                                        width: 2,
                                                      ),
                                                      Text(
                                                        '1672',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0xffffffff),
                                                            fontSize: 9),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              )
                                        : Container(
                                            width: 0,
                                            height: 0,
                                          ),
                                  ],
                                ),
                                SizedBox(
                                  height: 3.5,
                                ),
                                Text(
                                  _anchorList.values.toList().length >= 6
                                      ? _anchorList.values.toList()[5] == null
                                          ? ''
                                          : _anchorList.values
                                                      .toList()[5]
                                                      .userName ==
                                                  ''
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[5]
                                                  .userName
                                      : '',
                                  style: TextStyle(
                                      color: Color(0xffffffff), fontSize: 9),
                                )
                              ],
                            ),
                            SizedBox(
                              width: 33,
                            ),
                            Column(
                              children: [
                                Stack(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.only(top: 18),
                                      child: CircleAvatar(
                                        radius: 32,
                                        backgroundImage: _anchorList.values
                                                    .toList()
                                                    .length >=
                                                7
                                            ? _anchorList.values.toList()[6] ==
                                                    null
                                                ? AssetImage(
                                                    'assets/images/yuyinempty.png')
                                                : NetworkImage(_anchorList
                                                            .values
                                                            .toList()[6]
                                                            .userAvatar ==
                                                        ''
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[6]
                                                        .userAvatar)
                                            : AssetImage(
                                                'assets/images/yuyinempty.png'),
                                      ),
                                    ),
                                    _anchorList.values.toList().length >= 7
                                        ? _anchorList.values.toList()[6] == null
                                            ? Container(
                                                width: 0,
                                                height: 0,
                                              )
                                            : Padding(
                                                padding: EdgeInsets.only(
                                                    top: 76, left: 10),
                                                child: Container(
                                                  width: 45,
                                                  height: 15,
                                                  decoration: BoxDecoration(
                                                      color: Color(0x80707070),
                                                      borderRadius:
                                                          BorderRadius.all(
                                                              Radius.circular(
                                                                  7.5))),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    children: [
                                                      Image.asset(
                                                        'assets/images/yuyinheart.png',
                                                        width: 8,
                                                        height: 7.5,
                                                      ),
                                                      SizedBox(
                                                        width: 2,
                                                      ),
                                                      Text(
                                                        '1672',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0xffffffff),
                                                            fontSize: 9),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              )
                                        : Container(
                                            width: 0,
                                            height: 0,
                                          ),
                                  ],
                                ),
                                SizedBox(
                                  height: 3.5,
                                ),
                                Text(
                                  _anchorList.values.toList().length >= 7
                                      ? _anchorList.values.toList()[6] == null
                                          ? ''
                                          : _anchorList.values
                                                      .toList()[6]
                                                      .userName ==
                                                  ''
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[6]
                                                  .userName
                                      : '',
                                  style: TextStyle(
                                      color: Color(0xffffffff), fontSize: 9),
                                )
                              ],
                            ),
                            SizedBox(
                              width: 33,
                            ),
                            Column(
                              children: [
                                Stack(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.only(top: 18),
                                      child: CircleAvatar(
                                        radius: 32,
                                        backgroundImage: _anchorList.values
                                                    .toList()
                                                    .length >=
                                                8
                                            ? _anchorList.values.toList()[7] ==
                                                    null
                                                ? AssetImage(
                                                    'assets/images/yuyinempty.png')
                                                : NetworkImage(_anchorList
                                                            .values
                                                            .toList()[7]
                                                            .userAvatar ==
                                                        ''
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[7]
                                                        .userAvatar)
                                            : AssetImage(
                                                'assets/images/yuyinempty.png'),
                                      ),
                                    ),
                                    _anchorList.values.toList().length >= 8
                                        ? _anchorList.values.toList()[7] == null
                                            ? Container(
                                                width: 0,
                                                height: 0,
                                              )
                                            : Padding(
                                                padding: EdgeInsets.only(
                                                    top: 76, left: 10),
                                                child: Container(
                                                  width: 45,
                                                  height: 15,
                                                  decoration: BoxDecoration(
                                                      color: Color(0x80707070),
                                                      borderRadius:
                                                          BorderRadius.all(
                                                              Radius.circular(
                                                                  7.5))),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    children: [
                                                      Image.asset(
                                                        'assets/images/yuyinheart.png',
                                                        width: 8,
                                                        height: 7.5,
                                                      ),
                                                      SizedBox(
                                                        width: 2,
                                                      ),
                                                      Text(
                                                        '1672',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0xffffffff),
                                                            fontSize: 9),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              )
                                        : Container(
                                            width: 0,
                                            height: 0,
                                          ),
                                  ],
                                ),
                                SizedBox(
                                  height: 3.5,
                                ),
                                Text(
                                  _anchorList.values.toList().length >= 8
                                      ? _anchorList.values.toList()[7] == null
                                          ? ''
                                          : _anchorList.values
                                                      .toList()[7]
                                                      .userName ==
                                                  ''
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[7]
                                                  .userName
                                      : '',
                                  style: TextStyle(
                                      color: Color(0xffffffff), fontSize: 9),
                                )
                              ],
                            ),
                            SizedBox(
                              width: 33,
                            ),
                            Column(
                              children: [
                                Stack(
                                  children: [
                                    Padding(
                                      padding: EdgeInsets.only(top: 18),
                                      child: CircleAvatar(
                                        radius: 32,
                                        backgroundImage: _anchorList.values
                                                    .toList()
                                                    .length >=
                                                9
                                            ? _anchorList.values.toList()[8] ==
                                                    null
                                                ? AssetImage(
                                                    'assets/images/yuyinempty.png')
                                                : NetworkImage(_anchorList
                                                            .values
                                                            .toList()[8]
                                                            .userAvatar ==
                                                        ''
                                                    ? 'https://img1.baidu.com/it/u=3254254623,2492769581&fm=26&fmt=auto&gp=0.jpg'
                                                    : _anchorList.values
                                                        .toList()[8]
                                                        .userAvatar)
                                            : AssetImage(
                                                'assets/images/yuyinempty.png'),
                                      ),
                                    ),
                                    _anchorList.values.toList().length >= 9
                                        ? _anchorList.values.toList()[8] == null
                                            ? Container(
                                                width: 0,
                                                height: 0,
                                              )
                                            : Padding(
                                                padding: EdgeInsets.only(
                                                    top: 76, left: 10),
                                                child: Container(
                                                  width: 45,
                                                  height: 15,
                                                  decoration: BoxDecoration(
                                                      color: Color(0x80707070),
                                                      borderRadius:
                                                          BorderRadius.all(
                                                              Radius.circular(
                                                                  7.5))),
                                                  child: Row(
                                                    mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .center,
                                                    children: [
                                                      Image.asset(
                                                        'assets/images/yuyinheart.png',
                                                        width: 8,
                                                        height: 7.5,
                                                      ),
                                                      SizedBox(
                                                        width: 2,
                                                      ),
                                                      Text(
                                                        '1672',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0xffffffff),
                                                            fontSize: 9),
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              )
                                        : Container(
                                            width: 0,
                                            height: 0,
                                          ),
                                  ],
                                ),
                                SizedBox(
                                  height: 3.5,
                                ),
                                Text(
                                  _anchorList.values.toList().length >= 9
                                      ? _anchorList.values.toList()[8] == null
                                          ? ''
                                          : _anchorList.values
                                                      .toList()[8]
                                                      .userName ==
                                                  ''
                                              ? '章鱼小丸子'
                                              : _anchorList.values
                                                  .toList()[8]
                                                  .userName
                                      : '',
                                  style: TextStyle(
                                      color: Color(0xffffffff), fontSize: 9),
                                )
                              ],
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                ),
                isShield
                    ? Container(
                        width: 0,
                        height: 0,
                      )
                    : Align(
                        alignment: Alignment.topLeft,
                        child: Padding(
                          padding: EdgeInsets.only(
                              left: SizeUtil.px(15), top: SizeUtil.px(300)),
                          child: ListView.builder(
                              itemCount: _popupGiftList.length,
                              controller: _scrollController,
                              shrinkWrap: true,
                              itemBuilder: (context, index) {
                                return GiftList(
                                  giftEntity: GiftEntity.fromJson(
                                    jsonDecode(_popupGiftList[index]),
                                  ),
                                  userInfoEntity: userInfoEntity,
                                );
                              }),
                        ),
                      ),
                isShield || _popupMessageList.length == 0
                    ? Container(
                        width: 0,
                        height: 0,
                      )
                    : PopUpMessageList(
                        popupMessageList: isBarrageON ? _popupMessageList : [],
                      ),
                isShield
                    ? Container(
                        width: 0,
                        height: 0,
                      )
                    : LiveMessageList(
                        messageList: _messageLogList,
                      ),
                Positioned(
                  bottom: MediaQuery.of(context).viewInsets.bottom,
                  left: 10,
                  right: 10,
                  child:
                      isShowComment ? getInputMessage() : getgetRoomBottomBar(),
                ),
              ],
            ),
          ),
        ));
  }

  ///获取房间内排行榜
  Future<void> getRoomLeaderBoard() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = RoomLeaderBoardRequest();
    request
        .add('room_id', currentRoomId)
        .add('type', 1)
        .addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == 0) {
      List<Map<String, dynamic>> listMap =
          new List<Map<String, dynamic>>.from(result['data']);
      List<LeaderBorardEntity> leader = [];
      for (int i = 0; i < listMap.length; i++) {
        leader.add(LeaderBorardEntity.fromJson(listMap[i]));
        int gold = int.parse(leader[i].gold);
        leader[i].gold = (gold / 10000).toString() + "万";
      }
      setState(() {
        leaderList = leader;
      });
    } else if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    } else {
      TxUtils.showToast(result['message'], context);
    }
  }

  ///获取房间内主播信息
  getRoomAnchor() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = NoticeAnchorRequest();
    request.add('room_id', currentRoomId).addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == 0) {
      setState(() {
        userInfoEntity1 = UserInfoEntity.fromJson(
            new Map<String, dynamic>.from(result['data']));
        isAttention();
      });
    } else if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    } else {
      TxUtils.showToast(result['message'], context);
    }
  }

  ///通过userid获取用户信息
  getUserInfos() async {
    String currLoginUserId = await TxUtils.getLoginUserId();
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = UserDetailsByUserIdRequest();
    request
        .add('userId', currLoginUserId)
        .add('type', 2)
        .addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    }
    setState(() {
      userInfoEntity = UserInfoEntity.fromJson(
          new Map<String, dynamic>.from(result['data']));
    });
  }

  Future<void> servingWheat(String currLoginUserId) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = UserDetailsByUserIdRequest();
    request
        .add('userId', currLoginUserId)
        .add('type', 2)
        .addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    }
    setState(() {
      userInfoEntity = UserInfoEntity.fromJson(
          new Map<String, dynamic>.from(result['data']));
      serWheat(userInfoEntity.userId1);
    });
  }

  ///上麦，首先需要调用userid
  Future<void> serWheat(int userId1) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = ServingWheatRequest();
    request
        .add('user_id', userId1)
        .add('room_id', currentRoomId)
        .addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    } else {
      TxUtils.showErrorToast(result['data'], context);
    }
  }

  ///上麦具体接口
  Future<void> downWheat(String parse) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = UserDetailsByUserIdRequest();
    request
        .add('userId', parse)
        .add('type', 2)
        .addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    }
    setState(() {
      userInfoEntity = UserInfoEntity.fromJson(
          new Map<String, dynamic>.from(result['data']));
      doWheat(userInfoEntity.userId1);
    });
  }

  ///下麦具体接口
  Future<void> doWheat(int userId1) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = DownWheatRequest();
    request
        .add('user_id', userId1)
        .add('room_id', currentRoomId)
        .addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    } else {
      TxUtils.showErrorToast(result['data'], context);
    }
  }

  Future<void> getInitData() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = UserInfoRequest();
    request.add('type', 2).addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    }
    setState(() {
      userInfoEntity = UserInfoEntity.fromJson(
          new Map<String, dynamic>.from(result['data']));
    });
  }

  ///是否关注主播
  isAttention() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = AttentionAnchorRequest();
    request
        .add('anchor_id', userInfoEntity1.userId1)
        .addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == 0) {
      setState(() {
        isFollowed = result['data'];
      });
    } else if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    } else {
      TxUtils.showToast(result['message'], context);
    }
  }

  ///关注主播
  Future<void> attentionAnchor() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String appToken = prefs.getString('app-token');
    BaseRequest request = AttentionRoomRequest();
    request
        .add('user_id', userInfoEntity1.userId1)
        .add('type', 2)
        .addHeader('usertoken', appToken);
    var result = await HiNet.getInstance().fire(request);
    if (result['code'] == 0) {
      TxUtils.showToast(result['data'], context);
      setState(() {
        isFollowed = true;
      });
    } else if (result['code'] == -1) {
      TxUtils.showErrorToast('登录失效，请重新登录', context);
      Navigator.pop(context);
      Navigator.of(context).push(MaterialPageRoute(
        builder: (context) {
          return LoginPage(
            arguments: {'loginCode': '-1'},
          );
        },
      ));
    } else {
      TxUtils.showToast(result['message'], context);
    }
  }

  //显示底部弹框的功能
  void showBottomSheet() {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
        builder: (BuildContext context) {
          //构建弹框中的内容
          return buildBottomSheetWidget(context);
        },
        context: context);
  }

  Widget buildBottomSheetWidget(BuildContext context) {
    return Container(
      height: 158,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(20), topRight: Radius.circular(20))),
      child: Column(
        children: [
          SizedBox(
            height: 15.5,
          ),
          Text(
            '对 ' + userInfoEntity1.nickname,
            style: TextStyle(fontSize: 16, color: Color(0xff333333)),
          ),
          SizedBox(
            height: 26,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              InkWell(
                child: Column(
                  children: [
                    Image.asset(
                      'assets/images/voice_userinfo.png',
                      width: 45,
                      height: 45,
                    ),
                    SizedBox(
                      height: 15.5,
                    ),
                    Text(
                      '资料',
                      style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                    )
                  ],
                ),
                onTap: () {},
              ),
              SizedBox(
                width: 26.5,
              ),
              InkWell(
                child: Column(
                  children: [
                    Image.asset(
                      'assets/images/voice_nospeak.png',
                      width: 45,
                      height: 45,
                    ),
                    SizedBox(
                      height: 15.5,
                    ),
                    Text(
                      '禁言',
                      style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                    )
                  ],
                ),
                onTap: () {},
              ),
              SizedBox(
                width: 26.5,
              ),
              InkWell(
                child: Column(
                  children: [
                    Image.asset(
                      'assets/images/voice_down.png',
                      width: 45,
                      height: 45,
                    ),
                    SizedBox(
                      height: 15.5,
                    ),
                    Text(
                      '下麦',
                      style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                    )
                  ],
                ),
                onTap: () {},
              ),
              SizedBox(
                width: 26.5,
              ),
              InkWell(
                child: Column(
                  children: [
                    Image.asset(
                      'assets/images/voice_follew.png',
                      width: 45,
                      height: 45,
                    ),
                    SizedBox(
                      height: 15.5,
                    ),
                    Text(
                      '关注Ta',
                      style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                    )
                  ],
                ),
                onTap: () {},
              ),
              SizedBox(
                width: 26.5,
              ),
              InkWell(
                child: Column(
                  children: [
                    Image.asset(
                      'assets/images/voice_give_gift.png',
                      width: 45,
                      height: 45,
                    ),
                    SizedBox(
                      height: 15.5,
                    ),
                    Text(
                      '送礼',
                      style: TextStyle(fontSize: 12, color: Color(0xff999999)),
                    )
                  ],
                ),
                onTap: () {},
              )
            ],
          )
        ],
      ),
    );
  }
}
